package com.punch.order.design;


import cn.hutool.core.collection.CollUtil;
import com.punch.common.exception.BusinessException;
import com.punch.order.exception.OrderExceptionEnum;

import java.util.Map;

public class OrderContextFactory {

    private Map<String, PayStrategy> strategyMap = CollUtil.newHashMap(2);

    public Map<String, PayStrategy> getStrategyMap() {
        return strategyMap;
    }

    public void setStrategyMap(Map<String, PayStrategy> strategyMap) {
        this.strategyMap = strategyMap;
    }


    public PayContext getContext(String payContextKey) throws BusinessException {
        PayStrategy orderSignStrategy = strategyMap.get(payContextKey);
        if (orderSignStrategy == null)
            throw new BusinessException(OrderExceptionEnum.PAY_CHANNEL_NOT_SUPPORT);
        PayContext orderSignContext = new PayContext(orderSignStrategy);
        return orderSignContext;
    }
}
